//
//  MainViewController.swift
//  YBWeiBo
//
//  Created by 都勇博 on 2016/12/3.
//  Copyright © 2016年 都勇博. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        //设置tabbar颜色
        tabBar.tintColor = UIColor.orange
        
        addChildViewController(childController: HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(childController: MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(childController: DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(childController: ProfileTableViewController(), title: "我的", imageName: "tabbar_profile")
        
    }
    
    /// 初始化子控制器
    ///
    /// - Parameters:
    ///   - childController: 需要初始化的子控制器
    ///   - title: 子控制器的标题
    ///   - imageName: 子控制器的图片名称
    
    private func addChildViewController(childController: UIViewController,title:String, imageName: String){
        // 1.创建首页
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")
        childController.title = title
        
        // 2.包装一个导航控制器
        let nav = UINavigationController()
        nav.addChildViewController(childController)
        
        // 3.将导航控制器添加到当前控制器上
        addChildViewController(nav)

    }
}
